import Vue from 'vue'
import VueRouter from 'vue-router'
// 页面加载进度
import 'nprogress/nprogress.css'; // Progress 进度条样式
import NProgress from 'nprogress'; // Progress 进度条
NProgress.configure({
    easing: 'ease', // 动画方式
    speed: 600, // 递增进度条的速度
    showSpinner: true, // 是否显示加载ico
    trickleSpeed: 200, // 自动递增间隔
    minimum: 0.3, // 初始化时的最小百分比
})

// 前进缓存
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = async function push(location) {
    this.app.$route.meta.operatingMethod = 'push'
    return originalPush.call(this, location).catch(err => err)
}

// 后退清除缓存
VueRouter.prototype.goBack = function go(number) {
    this.app.$route.meta.operatingMethod = 'goBack'
    window.history.go(number)
}

// 归属于 无痕后退
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location) {
    this.app.$route.meta.operatingMethod = 'replace'
    return originalReplace.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
    // {
    //     path: '/',
    //     redirect: {
    //         path: '/',
    //     }
    // },

    // {
    //     path: "/",
    //     redirect: "/home",
    // },

    {
        path: '/',
        name: 'academy',
        component: _ => import('../views/academy-info.vue'),
        meta: {
            title: "展示页"
        }
    },

    {
        path: '/academyDetails',
        name: 'academyDetails',
        component: _ => import('../views/academy-details.vue'),
        meta: {
            title: "详情页面"
        }
    },

    {
        // 404配置
        path: '*',
        meta: {
            title: '404',
        },
        component: _ => import('@/views/root/not-found'),

    },

    // {
    //     path: '*',
    //     redirect: '/404'
    // }
]

const router = new VueRouter({
    // mode: 'mo',
    base: process.env.BASE_URL,
    routes
})




router.afterEach((to, from) => {
    document.querySelector('.main-loading-bg').style.display = 'none'
    NProgress.done()
})

router.beforeEach((to, from, next) => {
    console.log(to, from)
    NProgress.start()
    next()
})

export default router
